// JavaScript Document
function checkLoginForm()
{
	var username = document.getElementById("admin_name");
	var password = document.getElementById("admin_pwd");
	var validCode = document.getElementById("validCode");
	var s =	(/^\w+$/);
	var p =	(/[;'#]+/);
	if(username.value == '')
	{
		alert("username is required!");
		username.focus();
		return false;		
	}
	if(!s.test(username.value))
	{
		alert("Invalid inputs!");
		username.focus();
		return false;
	}
	if(password.value == '')
	{
		alert("password is required!");
		password.focus();
		return false;		
	}
	if(p.test(password.value))
	{
		alert("Invalid inputs!");
		password.focus();
		return false;
	}
	if(validCode.value == '')
	{
		alert("validcode is required!");
		validCode.focus();
		return false;		
	}
	else
		return true;
}
function openwin(url,wid,hei,left,top)              //弹出小窗口　源文件，宽，长；
{
open(url,'','width='+wid+',height='+hei+',scrollbars=1,resizable=yes,top='+top+',left='+left);
}

function PrintClick()
{
	window.print();
}
function PrintPreview()
{	
	var WebBrowser = document.getElementById("WebBrowser");
	WebBrowser.Execwb(7,1);//打印预览
    return false;
}


function Redirect(target,type){
	
/* redirect to a new location OR pop up a new window 
 * variable: target	-> redirect to
 * variable: type	-> location to a new URL OR pop up window OR other
 */
	
  switch (type){
  	case 1:
  	  window.parent.location = target; 
	  break;
	case 2:	  
		var HEIGHT = 500;
		var WIDTH = 700;		window.open(target,"detail","height="+HEIGHT+",width="+WIDTH+",top=20,left=20,location=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,"); 

	  break;
	case 3:	  
		var HEIGHT = 400;
		var WIDTH = 540;		window.open(target,"edit","height="+HEIGHT+",width="+WIDTH+",top=200,left=200,location=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,"); 

	  break;
	case 4:
	  window.showModalDialog(target,"choose","Height: 200; Width: 275; help: no");
	  break;
			case 5:	  
		var HEIGHT = 400;
		var WIDTH = 540;		window.open(target,"edit","height="+HEIGHT+",width="+WIDTH+",top=200,left=200,location=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,"); 

	  break;
		
		case 6:	  
		var HEIGHT = 400;
		var WIDTH = 540;		window.open(target,"edit","height="+HEIGHT+",width="+WIDTH+",top=200,left=200,location=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,"); 

	  break;
	  
	  			case 7:	  
		var HEIGHT = 500;
		var WIDTH = 850;		window.open(target,"edit","height="+HEIGHT+",width="+WIDTH+",top=200,left=200,location=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,"); 

	  break;

	default:	
	  break;
  }

}



function submitForm(theform, url, type) { 

 switch (type){

	case 1:
	
		if (eval(theform).Code.value == "" || eval(theform).Code.value == "Enter Code ..."){ 
			msg = "Please enter code!"; 
			window.alert (msg); 
			eval(theform).Code.focus(); 
			return false;
		}else{  
			eval(theform).action = url; 
			eval(theform).submit(); 
		}

		break;

	case 2:

		eval(theform).action = url; 
		eval(theform).submit(); 

		break;

	case 3:
	
		if (validate_email(eval(theform).Email.value)== false){ 
			msg = "Invalid Email!"; 
			window.alert (msg); 
			eval(theform).Email.focus(); 
			//return false;
		}else{  
			eval(theform).action = url; 
			eval(theform).submit(); 
		}

		break;

	defalut:

		break;
 }

} 

function validate_email(email)
{
  if (!validate_ascii_data (email)) {
    return false
  }

  var invalidChars = "\"|&;<>!*\'\\"   ;

  for (var i = 0; i < invalidChars.length; i++) {
    if (email.indexOf(invalidChars.charAt(i)) != -1) {
      return false;
    }
  }
 
  if (email.indexOf("@")==-1){
     return false;
  }
        
  if (email.indexOf(" ") != -1){
    return false;
  }

  if (window.RegExp) {

    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    
    var reg1 = new RegExp (reg1str);
    var reg2 = new RegExp (reg2str);
    if (reg1.test(email) || !reg2.test(email)) {
      return false;
    }
  }
  return true;
}

function validate_ascii_data(urstr)
{
  var i; var result;
  for(i=0; i<urstr.length; i++) {
    if((urstr.charAt(i) < " ") || (urstr.charAt(i) > "~"))
      return false;
  }
  return true;
}
